package logic

import (
	"bw-renting/user-rpc/userclient"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserEditAvatarLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserEditAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserEditAvatarLogic {
	return &UserEditAvatarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 修改用户头像
func (l *UserEditAvatarLogic) UserEditAvatar(req *types.EditUserAvatarReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.UserServer.UserModifyAvatar(context.Background(), &userclient.ModifyAvatarReq{
		UserID:    int64(req.UserId),
		AvatarUrl: req.Imgs,
	})
	if res.Status != 1 {
		return &types.Data{
			Code:    500,
			Message: "上传失败",
		}, nil
	}
	return &types.Data{
		Code:    0,
		Message: "上传成功",
		Data:    map[string]string{"avatarURL": req.Imgs},
	}, nil

}
